#include "proccessbar.h"

const char* lable = "|/-\\";

/*
void process()
{
    char buf[MAX];
    memset(buf,'\0',sizeof(buf));   
    int cnt = 0;
    buf[0] = Head;
    while(cnt <= 100)
    {
        printf("[%-100s][%-3d%%][%c]\r",buf,cnt,lable[cnt%4]);
        fflush(stdout);
        buf[cnt++] = Body;
        if(cnt < 100)
        {
            buf[cnt] = Head;
        }
        usleep(100000);
    }
    printf("\n");
}
*/
char buf[MAX] = {0};
void process(double rate)
{
    static int cnt = 0;
    int n = strlen(lable);
    if(rate <= 1.0)
        buf[0] = Head;
    printf("[%-100s][%.1f%%][%c]\r",buf,rate,lable[cnt%n]);
    fflush(stdout);
    buf[(int)rate] = Body;
    if((int)rate+1 < 100)
        buf[(int)rate+1] = Head;
    if(rate >= 100.0) 
        printf("\n");
    cnt++;
    cnt %= n;
}



